<template>
  <block>
    <view v-for="(item,index) in newMenus" :key="index" class="my-tabbar"
      v-if="item.pagePath == '/pages/plans/index' ? (hasMenuPer && showPlanMenu) : !item.hidden">
      <view hover-class="none" class="weui-flex__item menu-item" @click="goToTab(item.pagePath)"
        :style="item.active? 'color: '+(item.selectedColor? item.selectedColor : selectedColor) : ''">
        <image :src="item.selectedIconPath" v-if="item.active" class="img"></image>
        <image :src="item.iconPath" v-if="!item.active" class="img"></image>
        <text class='tabbar_text'>{{item.text}}</text>
      </view>
    </view>
  </block>
</template>

<script>
  import { getTenantId, getDriverId, getPurchaseModel } from '@/utils/auth';
  import { getInfo } from '@/api/login';
  export default {
    name: 'custom-tabbar',
    data() {
      return {
        showPlanMenu: false,
        hasMenuPer: true,
        color: '#333',
        newMenus: [],
        selectedColor: '#1aad19',
        backgroundColor: '#1aad19',
        position: 'bottom',
        borderStyle: '#ccc'
      }
    },
    props: {
      list: {
        type: Array,
        default: []
      },
    },
    async onShow() {
      let purmodel = await getPurModel()
      if (purmodel.code == 0) {
        this.showPlanMenu = purmodel.data.purchaseBizMode == 1 ? true : false
      }
      let permissionsLists = [];
      let plists = await getInfo({
        enterId: getTenantId(),
        userId: getDriverId()
      });
      permissionsLists = plists?.data?.permissions || [];
      this.hasMenuPer = permissionsLists.some(
        (item) => item == 'plan:view'
      );
    },
    created() {
      this.newMenus = this.list.filter(item => {
        return !item.hidden
      })
    },
    methods: {
      goToTab(url) {
        wx.switchTab({
          url: url  // 需要跳转的 tab 页路径
        })
      }
    },
  };
</script>

<style lang="scss" scoped>

</style>